package ch.unibe.jogeasy;

import android.app.ProgressDialog;
import android.os.Bundle;

import com.google.android.maps.GeoPoint;

public class MyListener implements RecognitionListener {
	ProgressDialog pd;
	TracksActivity ta;
	MainActivity ma;

	public MyListener(TracksActivity ta) {
		this.ta = ta;
	}

	public MyListener(MainActivity ma) {
		this.ma = ma;
	}

	public void setDialog(ProgressDialog pd) {
		this.pd = pd;
	}

	public void onResults(Bundle b) {
	}

	@Override
	public void onPartialResults(Bundle b) {
		final String hyp = b.getString("hyp");
		System.out.println("Partial HYP:" + hyp);
	}

	@Override
	public void onError(int err) {
		System.out.println("Error code: " + err);

	}

	public static Long[] convertLongStringToArray(String s) {
		if (s.length() < 1) {
			return new Long[0];
		}
		String[] arr = s.split(",");
		Long[] longs = new Long[arr.length];
		for (int i = 0; i < arr.length; i++) {
			longs[i] = Long.parseLong(arr[i]);
		}
		return longs;
	}

	public static Double[] convertDoubleStringToArray(String s) {
		if (s.length() < 1) {
			return new Double[0];
		}
		String[] arr = s.split(",");
		Double[] doubles = new Double[arr.length];
		for (int i = 0; i < arr.length; i++) {
			doubles[i] = Double.parseDouble(arr[i]);
		}
		return doubles;
	}

	public static GeoPoint[] convertGeoPointStringToArray(String s) {
		if (s.length() < 1) {
			return new GeoPoint[0];
		}
		String[] arr = s.split(",");
		GeoPoint[] geoPoints = new GeoPoint[arr.length];
		String[] point = new String[2];
		for (int i = 0; i < arr.length; i++) {
			point = arr[i].split(";");
			geoPoints[i] = new GeoPoint(Integer.parseInt(point[0]),
					Integer.parseInt(point[1]));
		}
		return geoPoints;
	}
}
